package components;

import support.State;
import exceptions.NotInValidStateException;

public class Engine {

	private int speed;
	private State engineState;

	public void startEngine() throws NotInValidStateException {
		engineState = State.ON;
//		increaseSpeed();
	}

	public void stopEngine() throws NotInValidStateException {
		decreaseSpeed(0);
		engineState = State.OFF;
	}

	public void increaseSpeed(int speed) {
		while (this.speed <= speed) {
			this.speed += 100;
			System.out.println("Increasing engine speed to:" + this.speed);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public void decreaseSpeed(int speed) {
		while (this.speed > speed) {
			this.speed -= 100;
			System.out.println("Decreasing engine speed to:" + this.speed);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public int getSpeed() {
		return speed;
	}

//	public void setSpeed(int speed) {
//		this.speed = speed;
//	}

	public State getState() {
		return engineState;
	}

//	public void setState(State state) {
//		this.engineState = state;
//	}

}
